package com.demo.model;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class ResultMsg <T>{
    private Integer code; // 状态码
    private String msg; //状态描述
    private T data; //数据



    /**
     * 操作成功
     * @param data
     * @return
     * @param <T>
     */
    public static <T> ResultMsg<T> OK(T data){
        return ResultMsg.<T>builder()
                .code(CodeEnum.SUCCESS.getCode())
                .msg(CodeEnum.SUCCESS.getDesc())
                .data(data)
                .build();
    }
    public static <T> ResultMsg<T> OK(CodeEnum codeEnum){
        return ResultMsg.<T>builder()
                .code(codeEnum.SUCCESS.getCode())
                .msg(codeEnum.SUCCESS.getDesc())
                .data(null)
                .build();
    }

    /**
     * 操作失败
     * @param codeEnum
     * @return
     * @param <T>
     */
    public static <T> ResultMsg<T> fail(CodeEnum codeEnum){
        return ResultMsg.<T>builder()
                .code(codeEnum.getCode())
                .msg(codeEnum.getDesc())
                .data(null)
                .build();
    }
}
